<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class Member extends CI_Controller {
	
	function __construct() {
		parent::__construct ();
	
	}
	
	public function index() {
		$id = $this->input->get ( "id" );
		if (! isset ( $id ) || $id == '') {
			$this->load->view ( 'error' );
			return;
		}
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			/*if ($member ['id'] == $id) {
				redirect ( "member/main" );
			} else {*/
				redirect ( 'tamember?id=' . $id );
//			}
		} else {
			redirect ( 'tamember?id=' . $id );
		}
	}
	//	到登陆页面
	public function tologin() {
		$eData = array ();
		$cap = $this->createcap ();
		$this->session->set_userdata ( 'cap', $cap );
		$eData ['cap'] = $cap;
		$eData ['gourl'] = $this->input->get ( 'gourl' );
		$this->load->view ( 'login', $eData );
	}
	//	登陆
	public function login() {
		$eData = array ();
		$this->load->library ( 'form_validation' );
		$this->form_validation->set_error_delimiters ( '', '' );
		$this->form_validation->set_rules ( 'email', '邮件', 'trim|required|max_length[60]|xss_clean' );
		$this->form_validation->set_rules ( 'password', '密码', 'trim|required|max_length[32]|xss_clean' );
		$this->form_validation->set_rules ( 'captcha', '验证码', 'trim|required|max_length[32]|xss_clean' );
		$cap = $this->input->post ( 'captcha' );
		$gourl = $this->input->get ( 'gourl' );
		$eData ['gourl'] = $gourl;
		if ($this->checkCap ( $cap ) == false) {
			$eData ['errorMsg'] = '验证码错误！';
			$cap = $this->createcap ();
			$this->session->set_userdata ( 'cap', $cap );
			$eData ['cap'] = $cap;
			$this->load->view ( 'login', $eData );
			return;
		}
		$cap = $this->createcap ();
		$this->session->set_userdata ( 'cap', $cap );
		$eData ['cap'] = $cap;
		if ($this->form_validation->run () == TRUE) {
			$this->db->where ( 'email', $this->input->post ( 'email' ) );
			$this->db->where ( 'password', md5 ( $this->input->post ( 'password' ) ) );
			
			$member = $this->db->get ( 'member' )->row_array ();
			if ($member != null) {
				$this->session->set_userdata ( 'member', $member );
				
				if (isset ( $gourl ) && $gourl != null && $gourl != '') {
					redirect ( $gourl );
				} else {
					redirect ( "member/main" );
				}
			
			} else {
				$eData ['errorMsg'] = '邮箱或密码错误！';
				$this->load->view ( 'login', $eData );
			}
		
		} else {
			$eError = validation_errors ();
			$eError = preg_replace ( '/\n/is', '<br />', $eError );
			$eData ['errorMsg'] = $eError;
			
			$this->load->view ( 'login', $eData );
		}
	
	}
	//到注册页面	
	public function toreg() {
		$eData = array ();
		$eData ['cap'] = $this->createcap ();
		$this->session->set_userdata ( 'cap', $eData ['cap'] );
		
		$this->db->where ( 'name', 'qstTip' );
		$eData ['qstTipList'] = $this->db->get ( 'codevalue' )->result_array ();
		$this->load->view ( 'reg', $eData );
	}
	//加载认证码
	public function loadcap() {
		header ( "Content-Type: text/html; charset=utf-8" );
		$cap = $this->createcap ();
		$this->session->set_userdata ( 'cap', $cap );
		
		$ret ['image'] = $cap ['image'];
		$ret ['success'] = 'true';
		$ret ['msg'] = '得到验证码成功';
		echo json_encode ( $ret );
	}
	//生成验证码
	public function createcap() {
		$this->load->helper ( 'captcha' );
		$vals = array ('word' => rand ( 1000, 9999 ), 'img_path' => './yzm/', 'img_url' => base_url () . 'yzm/', 'img_width' => 80, 'img_height' => 25, 'expiration' => 10 );
		$cap = create_captcha ( $vals );
		return $cap;
	}
	//注册
	public function reg() {
		$eData = array ();
		$captcha = $this->input->post ( 'captcha' );
		header ( "Content-Type: text/html; charset=utf-8" );
		if ($this->checkCap ( $captcha ) == false) {
			$eData ['errorMsg'] = '验证码错误！';
			$this->load->view ( 'member/toreg', $eData );
		} else {
			$this->load->library ( 'form_validation' );
			$this->form_validation->set_error_delimiters ( '', '' );
			$this->form_validation->set_rules ( 'email', '邮件', 'trim|required|max_length[60]|xss_clean' );
			$this->form_validation->set_rules ( 'password', '密码', 'trim|required|max_length[32]|xss_clean' );
			$this->form_validation->set_rules ( 'rpassword', '确认密码', 'trim|required|max_length[32]|xss_clean' );
			$this->form_validation->set_rules ( 'username', '用户名', 'trim|required|max_length[60]|xss_clean' );
			$this->form_validation->set_rules ( 'pas_tip', '密码提示问题', 'trim|required|max_length[50]|xss_clean' );
			$this->form_validation->set_rules ( 'answer', '密码提示答案', 'trim|required|max_length[255]|xss_clean' );
			$this->form_validation->set_rules ( 'captcha', '验证码', 'trim|required|max_length[4]|xss_clean' );
			if ($this->form_validation->run () == TRUE) {
				
				$eData ['email'] = $this->input->post ( 'email' );
				$eData ['password'] = md5 ( $this->input->post ( 'password' ) );
				$eData ['username'] = $this->input->post ( 'username' );
				$eData ['pwdquestion'] = $this->input->post ( 'pas_tip' );
				$eData ['pwdanswer'] = $this->input->post ( 'answer' );
				$eData ['regtime'] = time ();
				$eData ['lastlogin'] = time ();
				$eData ['avatar'] = 'images/others/pic_64x64.png';
				
				$this->db->insert ( 'member', $eData );
				$eID = $this->db->insert_id ();
				$eData ['id'] = $eID;
				$this->session->set_userdata ( 'member', $eData );
				
				redirect ( "member/main" );
			} else {
				$eError = validation_errors ();
				$eError = preg_replace ( '/\n/is', '\\n', $eError );
				$eData ['errorMsg'] = $eError;
				$this->load->view ( 'member/toreg', $eData );
			}
		}
	
	}
	
	public function checkCap($captcha) {
		$cap = $this->session->userdata ( 'cap' );
		return $captcha == $cap ['word'];
	}
	
	public function main() {
		if ($this->checklogin ()) {
			$this->load->view ( 'member/main' );
		} else {
			$this->tologin ();
		}
	
	}
	
	public function logout() {
		$this->session->set_userdata ( 'member', null );
		redirect ( 'member/tologin' );
	}
	
	public function checklogin() {
		$member = $this->session->userdata ( 'member' );
		if ($member == null) {
			return false;
		} else {
			return true;
		}
	}
	
	public function tofollow() {
		$eData = array ();
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->where ( 'member', $member ['id'] );
			$followList = $this->db->get ( 'follow', 7, $ePage )->result_array ();
			$eData ['followList'] = $followList;
			
			$this->db->where ( 'member', $member ['id'] );
			$eData ['followCount'] = $this->db->count_all_results ( 'follow' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 7;
			$eConfig ['num_links'] = 10;
			$eConfig ['base_url'] = site_url ( 'member/tofollow?1=1' );
			$eConfig ['total_rows'] = $eData ['followCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			$this->load->view ( 'member/follow', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	public function delfollow() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$fmember = $this->input->post ( 'fmember' );
			$this->db->where ( 'fmember', $fmember );
			$this->db->where ( 'member', $member ['id'] );
			
			$this->db->delete ( 'follow' );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			$cap = $this->createcap ();
			$this->session->set_userdata ( 'cap', $cap );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '删除关注成功';
			echo json_encode ( $ret );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	public function tofans() {
		$eData = array ();
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->where ( 'fmember', $member ['id'] );
			$fansList = $this->db->get ( 'follow', 7, $ePage )->result_array ();
			$eData ['fansList'] = $fansList;
			
			$this->db->where ( 'fmember', $member ['id'] );
			$eData ['fansCount'] = $this->db->count_all_results ( 'follow' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 7;
			$eConfig ['num_links'] = 10;
			$eConfig ['base_url'] = site_url ( 'member/tofans?1=1' );
			$eConfig ['total_rows'] = $eData ['fansCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			$this->load->view ( 'member/fans', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	public function delfans() {
		if ($this->checklogin ()) {
			$smember = $this->session->userdata ( 'member' );
			$member = $this->input->post ( 'member' );
			$this->db->where ( 'member', $member );
			$this->db->where ( 'fmember', $smember ['id'] );
			
			$this->db->delete ( 'follow' );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			$cap = $this->createcap ();
			$this->session->set_userdata ( 'cap', $cap );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '删除关注成功';
			echo json_encode ( $ret );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	public function invite() {
		if ($this->checklogin ()) {
			$this->load->view ( 'member/invite' );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	public function addstreet() {
		if ($this->checklogin ()) {
			$eData = array ();
			$this->load->model ( 'codevalue_model' );
			$eData ['areaList'] = $this->codevalue_model->getCodeValueList ( 'area' );
			$this->load->view ( 'member/addstreet', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	public function savestreet() {
		if ($this->checklogin ()) {
			$eData = array ();
			$this->load->library ( 'form_validation' );
			$this->form_validation->set_error_delimiters ( '', '' );
			$this->form_validation->set_rules ( 'street_name', '街道名称', 'trim|required|max_length[300]|xss_clean' );
			$this->form_validation->set_rules ( 'store_sorts', '所属区域', 'trim|required|max_length[100]|xss_clean' );
			$this->form_validation->set_rules ( 'culture', '历史文化', 'trim|required|xss_clean' );
			if ($this->form_validation->run () == TRUE) {
				
				$eConfig = array ();
				$eConfig ['upload_path'] = 'uploadfile/' . date ( 'Y' ) . '/' . date ( 'W' ) . '/';
				
				$this->mkFolder ( $eConfig ['upload_path'] );
				$eConfig ['allowed_types'] = 'jpg|bmp|gif|png';
				$eConfig ['file_name'] = time () . rand ( 1000, 9999 );
				$eConfig ['max_size'] = 1024 * 20;
				
				$this->load->library ( 'upload', $eConfig );
				if (! $this->upload->do_upload ( 'logo' )) {
					header ( "Content-Type: text/html; charset=utf-8" );
					echo '<body style="margin: 0; padding: 0;">
					<div style="font-size: 12px; color: #CC3300;">
					' . $this->upload->display_errors () . '
					<a href="' . site_url ( 'member/addstreet' ) . '">返回</a>
					</div>
					</body>';
				} else {
					$eUpLoad = $this->upload->data ();
					$newsPic = $eConfig ['upload_path'] . $eUpLoad ['file_name'];
					
					$eData ['name'] = $this->input->post ( 'street_name' ); //街道名称
					$eData ['ename'] = $this->input->post ( 'ename' ); //英文名称
					$eData ['area'] = $this->input->post ( 'store_sorts' ); //所属区域
					$eData ['history'] = $this->input->post ( 'culture' ); //历史文化
					$eData ['logo'] = $newsPic; //logo
					$eData ['createtime'] = time (); //创建时间
					

					$member = $this->session->userdata ( 'member' );
					$eData ['createid'] = $member ['id']; //创建人
					$eData ['creator'] = $member ['username']; //创建人昵称
					$this->db->insert ( 'street', $eData );
					$eID = $this->db->insert_id ();
					$eData ['id'] = $eID;
					
					redirect ( "member/main", $eData );
				}
			
			} else {
				$eError = validation_errors ();
				$eError = preg_replace ( '/\n/is', '\\n', $eError );
				$eData ['errorMsg'] = $eError;
				
				$this->load->model ( 'codevalue_model' );
				$eData ['areaList'] = $this->codevalue_model->getCodeValueList ( 'area' );
				$this->load->view ( 'member/addstreet', $eData );
			}
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function addedstreet() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->where ( 'createid', $member ['id'] );
			$streetList = $this->db->get ( 'street', 10, $ePage )->result_array ();
			$eData ['streetList'] = $streetList;
			
			$this->db->where ( 'createid', $member ['id'] );
			$eData ['streetCount'] = $this->db->count_all_results ( 'street' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 10;
			$eConfig ['num_links'] = 10;
			$eConfig ['base_url'] = site_url ( 'member/addedstreet?1=1' );
			$eConfig ['total_rows'] = $eData ['streetCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/addedstreet', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function mangedstreet() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->where ( 'manager', $member ['id'] );
			$streetList = $this->db->get ( 'street', 10, $ePage )->result_array ();
			$eData ['streetList'] = $streetList;
			
			$this->db->where ( 'manager', $member ['id'] );
			$eData ['streetCount'] = $this->db->count_all_results ( 'street' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 10;
			$eConfig ['num_links'] = 10;
			$eConfig ['base_url'] = site_url ( 'member/mangedstreet?1=1' );
			$eConfig ['total_rows'] = $eData ['streetCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/mangedstreet', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	public function quitmangstreet() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$street = $this->input->post ( 'street' );
			$this->db->where ( 'id', $street );
			
			$street_array = $this->db->get ( 'street' )->row_array ();
			header ( "Content-Type: text/html; charset=utf-8" );
			$ret = array ();
			if ($street_array ['manager'] == $member ['id']) {
				$eData = array ();
				$eData ['manager'] = '';
				$this->db->where ( 'id', $street );
				$this->db->update ( 'street', $eData );
				
				$ret ['success'] = 'true';
				$ret ['msg'] = '退出街道主任成功';
			} else {
				$ret ['success'] = 'false';
				$ret ['msg'] = '你不是该街道主任';
			}
			
			echo json_encode ( $ret );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	public function livestreet() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->select ( '*' );
			$this->db->from ( 'street' );
			$this->db->join ( 'livestreet', 'livestreet.street = street.id', 'inner' );
			$this->db->where ( 'livestreet.member', $member ['id'] );
			$this->db->limit ( 10, $ePage );
			
			$streetList = $this->db->get ()->result_array ();
			$eData ['streetList'] = $streetList;
			
			$this->db->select ( '*' );
			$this->db->from ( 'street' );
			$this->db->join ( 'livestreet', 'livestreet.street = street.id', 'inner' );
			$this->db->where ( 'livestreet.member', $member ['id'] );
			$eData ['streetCount'] = $this->db->count_all_results ();
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 10;
			$eConfig ['num_links'] = 10;
			$eConfig ['base_url'] = site_url ( 'member/livestreet?1=1' );
			$eConfig ['total_rows'] = $eData ['streetCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/livestreet', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	function dellivestreet() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$street = $this->input->post ( 'street' );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$this->db->where ( 'street', $street );
			$this->db->where ( 'member', $member ['id'] );
			$this->db->delete ( 'livestreet' );
			
			$ret = array ();
			$ret ['success'] = 'true';
			$ret ['msg'] = '退出街道主任成功';
			
			echo json_encode ( $ret );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function applymangstr() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$this->load->view ( 'member/applymangstr' );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function savemangstr() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$eData = array ();
			$eData ['type'] = 1;
			$eData ['name'] = $this->input->post ( 'street_name' );
			$eData ['code'] = $this->input->post ( 'street_id' );
			$eData ['phone'] = $this->input->post ( 'apply_phone' );
			$eData ['selfintro'] = $this->input->post ( 'user_info' );
			$eData ['status'] = 1;
			$eData ['applymember'] = $member ['id'];
			$eData ['applyuname'] = $member ['username'];
			$eData ['applytime'] = time ();
			
			$eID = $this->db->insert ( 'apply', $eData );
			redirect ( 'member/mangedstreet' );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function streetopic() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$eData = array ();
			
			$this->load->view ( 'member/streetopic', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	public function addstore() {
		if ($this->checklogin ()) {
			$eData = array ();
			$this->load->model ( 'codevalue_model' );
			$eData ['ycpp'] = $this->codevalue_model->getCodeValueList ( 'ycpp' );
			$eData ['tsqyList'] = $this->codevalue_model->getCodeValueList ( 'tsqy' );
			$eData ['shenghuoList'] = $this->codevalue_model->getCodeValueList ( 'shenghuo' );
			$eData ['storeperson'] = $this->codevalue_model->getCodeValueList ( 'storeperson' );
			$eData ['storespebus'] = $this->codevalue_model->getCodeValueList ( 'storespebus' );
			$this->load->view ( 'member/addstore', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	public function getfenlei() {
		$this->load->model ( 'codevalue_model' );
		$name = $this->input->post ( 'name' );
		$fenleiList = $this->codevalue_model->getCodeValueList ( $name );
		
		header ( "Content-Type: text/html; charset=utf-8" );
		
		$ret ['success'] = 'true';
		$ret ['fenleiList'] = $fenleiList;
		echo json_encode ( $ret );
	
	}
	
	public function savestore() {
		if ($this->checklogin ()) {
			$eData = array ();
			$this->load->library ( 'form_validation' );
			$this->form_validation->set_error_delimiters ( '', '' );
			$this->form_validation->set_rules ( 'store_name', '小店名称', 'trim|required|max_length[300]|xss_clean' );
			$this->form_validation->set_rules ( 'store_id', '所在街道编号', 'trim|required|max_length[32]|xss_clean' );
			$this->form_validation->set_rules ( 'store_url', '小店地址', 'trim|required|xss_clean' );
			if ($this->form_validation->run () == TRUE) {
				
				$eConfig = array ();
				$eConfig ['upload_path'] = 'uploadfile/' . date ( 'Y' ) . '/' . date ( 'W' ) . '/';
				
				$this->mkFolder ( $eConfig ['upload_path'] );
				$eConfig ['allowed_types'] = 'jpg|bmp|gif|png';
				$eConfig ['file_name'] = time () . rand ( 1000, 9999 );
				$eConfig ['max_size'] = 1024 * 20;
				
				$this->load->library ( 'upload', $eConfig );
				if (! $this->upload->do_upload ( 'photo' )) {
					header ( "Content-Type: text/html; charset=utf-8" );
					echo '<body style="margin: 0; padding: 0;">
					<div style="font-size: 12px; color: #CC3300;">
					' . $this->upload->display_errors () . '
					<a href="' . site_url ( 'member/addstore' ) . '">返回</a>
					</div>
					</body>';
				} else {
					$eUpLoad = $this->upload->data ();
					$newsPhoto = $eConfig ['upload_path'] . $eUpLoad ['file_name'];
					
					$eData ['name'] = $this->input->post ( 'store_name' ); //小店名称
					$eData ['street'] = $this->input->post ( 'store_id' ); //英文名称
					$eData ['address'] = $this->input->post ( 'store_url' ); //小店地址
					$eData ['eaddress'] = $this->input->post ( 'eaddress' ); //英文地址
					$eData ['storetype'] = $this->input->post ( 'storetype' ); //小店分类
					$eData ['storetypes'] = $this->input->post ( 'storetypes' ); //小店分类的子分类
					$eData ['storebrand'] = $this->input->post ( 'storebrand' ); //原创品牌
					$eData ['storeperson'] = $this->input->post ( 'storeperson' ); //名人开店
					$eData ['storespebus'] = $this->input->post ( 'storespebus' ); //特色商圈
					$eData ['storespebuss'] = $this->input->post ( 'storespebuss' ); //特色商圈子类
					$eData ['style'] = $this->input->post ( 'style' ); //小店风格
					$eData ['bustime'] = $this->input->post ( 'bustime' ); //营业时间
					$eData ['phone'] = $this->input->post ( 'phone' ); //联系电话
					$eData ['history'] = $this->input->post ( 'history' ); //小店文化
					$eData ['tags'] = $this->input->post ( 'tags' ); //标签
					$eData ['photo'] = $newsPhoto; //照片
					$eData ['map'] = $this->input->post ( 'map' );
					$eData ['storespebuss'] = $this->input->post ( 'storespebuss' ); //特色商圈子类
					

					$eData ['createtime'] = time (); //创建时间
					

					$member = $this->session->userdata ( 'member' );
					$eData ['createid'] = $member ['id']; //创建人
					$eData ['creator'] = $member ['username']; //创建人昵称
					$this->db->insert ( 'store', $eData );
					$eID = $this->db->insert_id ();
					$eData ['id'] = $eID;
					
					redirect ( "member/addstore", $eData );
				}
			
			} else {
				$eError = validation_errors ();
				$eError = preg_replace ( '/\n/is', '\\n', $eError );
				$eData ['errorMsg'] = $eError;
				
				$this->load->model ( 'codevalue_model' );
				$eData ['storebrand'] = $this->codevalue_model->getCodeValueList ( 'storebrand' );
				$eData ['storeperson'] = $this->codevalue_model->getCodeValueList ( 'storeperson' );
				$eData ['storespebus'] = $this->codevalue_model->getCodeValueList ( 'storespebus' );
				$this->load->view ( 'member/addstore', $eData );
			}
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function addedstore() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->where ( 'createid', $member ['id'] );
			$storeList = $this->db->get ( 'store', 10, $ePage )->result_array ();
			$eData ['storeList'] = $storeList;
			
			$this->db->where ( 'createid', $member ['id'] );
			$eData ['storeCount'] = $this->db->count_all_results ( 'store' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 10;
			$eConfig ['num_links'] = 10;
			$eConfig ['base_url'] = site_url ( 'member/addedstore?1=1' );
			$eConfig ['total_rows'] = $eData ['storeCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/addedstore', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function editstore() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$eData = array();
			$this->load->library('form_validation');
			$this->form_validation->set_error_delimiters('<div class="eError">', '</div>');
			$id = $this->input->get('id');
			$this->db->where('id',$id);
			$eData['store'] = $this->db->get('store')->row_array();
			
			$this->load->model ( 'codevalue_model' );
			$eData ['ycpp'] = $this->codevalue_model->getCodeValueList ( 'ycpp' );
			$eData ['tsqyList'] = $this->codevalue_model->getCodeValueList ( 'tsqy' );
			$eData ['shenghuoList'] = $this->codevalue_model->getCodeValueList ( 'shenghuo' );
			$eData ['storeperson'] = $this->codevalue_model->getCodeValueList ( 'storeperson' );
			$eData ['storespebus'] = $this->codevalue_model->getCodeValueList ( 'storespebus' );
			
			$this->load->view ( 'member/editstore', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function editsavestore(){
		if ($this->checklogin ()) {
			$eData = array ();
			$this->load->library ( 'form_validation' );
			$this->form_validation->set_error_delimiters ( '', '' );
			$this->form_validation->set_rules ( 'store_name', '小店名称', 'trim|required|max_length[300]|xss_clean' );
			$this->form_validation->set_rules ( 'store_id', '所在街道编号', 'trim|required|max_length[32]|xss_clean' );
			$this->form_validation->set_rules ( 'store_url', '小店地址', 'trim|required|xss_clean' );
			if ($this->form_validation->run () == TRUE) {
				$id = $this->input->post( 'id' ); //小店名称
				$eConfig = array ();
				$eData ['name'] = $this->input->post ( 'store_name' ); //小店名称
				$eData ['street'] = $this->input->post ( 'store_id' ); //英文名称
				$eData ['address'] = $this->input->post ( 'store_url' ); //小店地址
				$eData ['eaddress'] = $this->input->post ( 'eaddress' ); //英文地址
				$eData ['storetype'] = $this->input->post ( 'storetype' ); //小店分类
				$eData ['storetypes'] = $this->input->post ( 'storetypes' ); //小店分类的子分类
				$eData ['storebrand'] = $this->input->post ( 'storebrand' ); //原创品牌
				$eData ['storeperson'] = $this->input->post ( 'storeperson' ); //名人开店
				$eData ['storespebus'] = $this->input->post ( 'storespebus' ); //特色商圈
				$eData ['storespebuss'] = $this->input->post ( 'storespebuss' ); //特色商圈子类
				$eData ['style'] = $this->input->post ( 'style' ); //小店风格
				$eData ['bustime'] = $this->input->post ( 'bustime' ); //营业时间
				$eData ['phone'] = $this->input->post ( 'phone' ); //联系电话
				$eData ['history'] = $this->input->post ( 'history' ); //小店文化
				$eData ['tags'] = $this->input->post ( 'tags' ); //标签
				
				$eData ['map'] = $this->input->post ( 'map' );
				$eData ['storespebuss'] = $this->input->post ( 'storespebuss' ); //特色商圈子类
				
				$eData['id'] = $id;
				
				
				$eConfig ['upload_path'] = 'uploadfile/' . date ( 'Y' ) . '/' . date ( 'W' ) . '/';
				$this->mkFolder ( $eConfig ['upload_path'] );
				$eConfig ['allowed_types'] = 'jpg|bmp|gif|png';
				$eConfig ['file_name'] = time () . rand ( 1000, 9999 );
				$eConfig ['max_size'] = 1024 * 20;
				$this->load->library ( 'upload', $eConfig );
				if($this->upload->do_upload ( 'photo' )){
					
					$eUpLoad = $this->upload->data ();
					$newsPhoto = $eConfig ['upload_path'] . $eUpLoad ['file_name'];
					$eData ['photo'] = $newsPhoto; //照片
				}

				$member = $this->session->userdata ( 'member' );
				$this->db->where('id',$id);
				$this->db->update ( 'store', $eData );
				
				redirect ( "member/addedstore", $eData );
			
			} else {
				$eError = validation_errors ();
				$eError = preg_replace ( '/\n/is', '\\n', $eError );
				$eData ['errorMsg'] = $eError;
				
				$eData = array();
				$this->load->library('form_validation');
				$this->form_validation->set_error_delimiters('<div class="eError">', '</div>');
				$this->db->where('id',$id);
				$eData['store'] = $this->db->get('store')->row_array();
				
				$this->load->model ( 'codevalue_model' );
				$eData ['ycpp'] = $this->codevalue_model->getCodeValueList ( 'ycpp' );
				$eData ['tsqyList'] = $this->codevalue_model->getCodeValueList ( 'tsqy' );
				$eData ['shenghuoList'] = $this->codevalue_model->getCodeValueList ( 'shenghuo' );
				$eData ['storeperson'] = $this->codevalue_model->getCodeValueList ( 'storeperson' );
				$eData ['storespebus'] = $this->codevalue_model->getCodeValueList ( 'storespebus' );
				
				$this->load->view ( 'member/editstore', $eData );
			}
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function applystore() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$this->load->view ( 'member/applystore' );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function saveapplystore() {
		if ($this->checklogin ()) {
			
			$eConfig ['upload_path'] = 'uploadfile/' . date ( 'Y' ) . '/' . date ( 'W' ) . '/';
			
			$this->mkFolder ( $eConfig ['upload_path'] );
			$eConfig ['allowed_types'] = 'jpg|bmp|gif|png';
			$eConfig ['file_name'] = time () . rand ( 1000, 9999 );
			$eConfig ['max_size'] = 1024 * 20;
			
			$this->load->library ( 'upload', $eConfig );
			if (! $this->upload->do_upload ( 'photo' )) {
				header ( "Content-Type: text/html; charset=utf-8" );
				echo '<body style="margin: 0; padding: 0;">
					<div style="font-size: 12px; color: #CC3300;">
					' . $this->upload->display_errors () . '
					<a href="' . site_url ( 'member/applystore' ) . '">返回</a>
					</div>
					</body>';
			} else {
				$member = $this->session->userdata ( 'member' );
				$eUpLoad = $this->upload->data ();
				$newsPhoto = $eConfig ['upload_path'] . $eUpLoad ['file_name'];
				
				$eData = array ();
				$eData ['type'] = 2;
				$eData ['name'] = $this->input->post ( 'store_name' );
				$eData ['code'] = $this->input->post ( 'store_id' );
				$eData ['url'] = $this->input->post ( 'store_url' );
				$eData ['phone'] = $this->input->post ( 'apply_phone' );
				$eData ['qq'] = $this->input->post ( 'qq' );
				$eData ['selfintro'] = $this->input->post ( 'user_info' );
				$eData ['status'] = 1;
				$eData ['photo'] = $newsPhoto;
				$eData ['applymember'] = $member ['id'];
				$eData ['applyuname'] = $member ['username'];
				$eData ['applytime'] = time ();
				
				$eID = $this->db->insert ( 'apply', $eData );
				redirect ( 'member/mangedstore' );
			}
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function mangedstore() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->where ( 'manager', $member ['id'] );
			$storeList = $this->db->get ( 'store', 10, $ePage )->result_array ();
			$eData ['storeList'] = $storeList;
			
			$this->db->where ( 'manager', $member ['id'] );
			$eData ['storeCount'] = $this->db->count_all_results ( 'store' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 10;
			$eConfig ['num_links'] = 10;
			$eConfig ['base_url'] = site_url ( 'member/mangedstore?1=1' );
			$eConfig ['total_rows'] = $eData ['storeCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/mangedstore', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function addblog() {
		if ($this->checklogin ()) {
			
			$this->load->view ( 'member/addblog' );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function saveblog() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$eData = array ();
			$eData ['title'] = $this->input->post ( 'daily_title' );
			$eData ['content'] = $this->input->post ( 'daily_info' );
			$eData ['member'] = $member ['id'];
			$eData ['membername'] = $member ['username'];
			$eData ['createtime'] = time ();
			$eData ['updatetime'] = time ();
			
			$eID = $this->db->insert ( 'blog', $eData );
			$this->load->view ( 'member/addblog' );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function mangblog() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->where ( 'member', $member ['id'] );
			$blogList = $this->db->get ( 'blog', 10, $ePage )->result_array ();
			$eData ['blogList'] = $blogList;
			
			$this->db->where ( 'member', $member ['id'] );
			$eData ['blogCount'] = $this->db->count_all_results ( 'blog' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 10;
			$eConfig ['num_links'] = 10;
			$eConfig ['base_url'] = site_url ( 'member/mangblog?1=1' );
			$eConfig ['total_rows'] = $eData ['blogCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/mangblog', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	public function delblog() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$blog_id = $this->input->post ( 'blogid' );
			$this->db->where ( 'id', $blog_id );
			
			$this->db->delete ( 'blog' );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '删除日志成功';
			echo json_encode ( $ret );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	function blogreply() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$this->load->view ( 'member/blogreply' );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function detail() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$this->db->where ( 'id', $member ['id'] );
			$eData = array ();
			$eData ['member'] = $this->db->get ( 'member' )->row_array ();
			$this->load->view ( 'member/detail', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function savedetail() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$member ['national'] = $this->input->post ( 'national' );
			$member ['residence'] = $this->input->post ( 'residence' );
			$member ['desc'] = $this->input->post ( 'desc' );
			
			$this->db->where ( 'id', $member ['id'] );
			$this->db->update ( 'member', $member );
			
			$this->session->set_userdata ( 'member', $member );
			header ( "Content-Type: text/html; charset=utf-8" );
			echo '<script type="text/javascript">
				alert("保存成功");
				window.location.href = "' . site_url ( 'member/detail' ) . '";
				</script>';
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function avatar() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$this->load->view ( 'member/avatar', $member );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function uploadavatar() {
		if ($this->checklogin ()) {
			$eConfig ['upload_path'] = 'uploadfile/' . date ( 'Y' ) . '/' . date ( 'W' ) . '/';
			
			$this->mkFolder ( $eConfig ['upload_path'] );
			$eConfig ['allowed_types'] = 'jpg|bmp|gif|png';
			$eConfig ['file_name'] = time () . rand ( 1000, 9999 );
			$eConfig ['max_size'] = 1024 * 20;
			
			$this->load->library ( 'upload', $eConfig );
			if (! $this->upload->do_upload ( 'avatar' )) {
				header ( "Content-Type: text/html; charset=utf-8" );
				echo '<body style="margin: 0; padding: 0;">
					<div style="font-size: 12px; color: #CC3300;">
					' . $this->upload->display_errors () . '
					<a href="' . site_url ( 'member/avatar' ) . '">返回</a>
					</div>
					</body>';
			} else {
				$eUpLoad = $this->upload->data ();
				header ( "Content-Type: text/html; charset=utf-8" );
				
				$ret ['image_url'] = $eConfig ['upload_path'] . $eUpLoad ['file_name'];
				$ret ['success'] = 'true';
				$ret ['msg'] = '上传头像成功';
				echo json_encode ( $ret );
			}
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function saveavatar() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$member ['avatar'] = $this->input->post ( 'avatar' );
			
			$this->db->where ( 'id', $member ['id'] );
			$this->db->update ( 'member', $member );
			$this->session->set_userdata ( 'member', $member );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function modifypwd() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$this->load->view ( 'member/modifypwd', $member );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function savepwd() {
		if ($this->checklogin ()) {
			header ( "Content-Type: text/html; charset=utf-8" );
			$member = $this->session->userdata ( 'member' );
			$old_pwd = $this->input->post ( 'before_pwd' );
			if (md5 ( $old_pwd ) != $member ['password']) {
				$ret ['success'] = 'false';
				$ret ['msg'] = '原密码不正确';
				echo json_encode ( $ret );
			} else {
				$new_pwd = $this->input->post ( 'update_pwd' );
				$member ['password'] = md5 ( $new_pwd );
				
				$this->db->where ( 'id', $member ['id'] );
				$this->db->update ( 'member', $member );
				$this->session->set_userdata ( 'member', $member );
				$ret ['success'] = 'sucess';
				$ret ['msg'] = '密码修改成功';
				echo json_encode ( $ret );
			}
		
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function albumlist() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$this->db->where ( 'member', $member ['id'] );
			$this->db->order_by ( 'createtime', 'DESC' );
			$albumList = $this->db->get ( 'album', 7, $ePage )->result_array ();
			$eData ['albumList'] = $albumList;
			
			$this->db->where ( 'member', $member ['id'] );
			$eData ['albumCount'] = $this->db->count_all_results ( 'album' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 7;
			$eConfig ['num_links'] = 7;
			$eConfig ['base_url'] = site_url ( 'member/albumlist?1=1' );
			$eConfig ['total_rows'] = $eData ['albumCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/albumlist', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function albumadd() {
		if ($this->checklogin ()) {
			$this->load->view ( 'member/albumadd' );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function albumsave() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$eConfig ['upload_path'] = 'uploadfile/' . date ( 'Y' ) . '/' . date ( 'W' ) . '/';
			
			$this->mkFolder ( $eConfig ['upload_path'] );
			$eConfig ['allowed_types'] = 'jpg|bmp|gif|png';
			$eConfig ['file_name'] = time () . rand ( 1000, 9999 );
			$eConfig ['max_size'] = 1024 * 20;
			
			$this->load->library ( 'upload', $eConfig );
			if (! $this->upload->do_upload ( 'cover' )) {
				header ( "Content-Type: text/html; charset=utf-8" );
				echo '<body style="margin: 0; padding: 0;">
					<div style="font-size: 12px; color: #CC3300;">
					' . $this->upload->display_errors () . '
					<a href="' . site_url ( 'member/avatar' ) . '">返回</a>
					</div>
					</body>';
			} else {
				
				$eUpLoad = $this->upload->data ();
				$eData ['cover'] = $eConfig ['upload_path'] . $eUpLoad ['file_name'];
				$eData ['name'] = $this->input->post ( 'album_name' );
				$eData ['desc'] = $this->input->post ( 'desc' );
				$eData ['createtime'] = time ();
				$eData ['modifytime'] = time ();
				$eData ['member'] = $member ['id'];
				$eID = $this->db->insert ( 'album', $eData );
				redirect ( 'member/albumlist' );
			}
		
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	public function albumdel() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$albumId = $this->input->post ( 'albumId' );
			$this->db->where ( 'id', $albumId );
			
			$this->db->delete ( 'album' );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '删除相册成功';
			echo json_encode ( $ret );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	function photolist() {
		if ($this->checklogin ()) {
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$member = $this->session->userdata ( 'member' );
			$this->db->where ( 'type', 1 );
			$this->db->where ( 'belongId', $member ['id'] );
			$this->db->order_by ( 'createtime', 'DESC' );
			$photoList = $this->db->get ( 'picture', 7, $ePage )->result_array ();
			$eData ['photoList'] = $photoList;
			
			$this->db->where ( 'type', 1 );
			$this->db->where ( 'belongId', $member ['id'] );
			$eData ['photoCount'] = $this->db->count_all_results ( 'picture' );
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 7;
			$eConfig ['num_links'] = 7;
			$eConfig ['base_url'] = site_url ( 'member/photolist' );
			$eConfig ['total_rows'] = $eData ['photoCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/photolist', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function streetpiclist() {
		if ($this->checklogin ()) {
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$member = $this->session->userdata ( 'member' );
			$this->db->select ( "picture.*,street.name,street.creator" );
			$this->db->from ( "picture" );
			$this->db->join ( "street", "street.id=picture.belongid" );
			$this->db->where ( 'type', 2 );
			$this->db->where ( 'street.manager', $member ['id'] );
			$this->db->limit ( 7, $ePage );
			$this->db->order_by ( 'picture.createtime', 'DESC' );
			$photoList = $this->db->get ()->result_array ();
			$eData ['photoList'] = $photoList;
			
			$this->db->select ( "*" );
			$this->db->from ( "picture" );
			$this->db->join ( "street", "street.id=picture.belongid" );
			$this->db->where ( 'type', 2 );
			$this->db->where ( 'street.manager', $member ['id'] );
			$eData ['photoCount'] = $this->db->count_all_results ();
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 7;
			$eConfig ['num_links'] = 7;
			$eConfig ['base_url'] = site_url ( 'member/photolist' );
			$eConfig ['total_rows'] = $eData ['photoCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/streetpiclist', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function storepiclist() {
		if ($this->checklogin ()) {
			$ePage = ( int ) $this->input->get ( 'page' );
			
			$member = $this->session->userdata ( 'member' );
			$this->db->select ( "picture.*,store.name,store.creator" );
			$this->db->from ( "picture" );
			$this->db->join ( "store", "store.id=picture.belongid" );
			$this->db->where ( 'type', 3 );
			$this->db->where ( 'store.manager', $member ['id'] );
			$this->db->limit ( 7, $ePage );
			$this->db->order_by ( 'picture.createtime', 'DESC' );
			$photoList = $this->db->get ()->result_array ();
			$eData ['photoList'] = $photoList;
			
			$this->db->select ( "*" );
			$this->db->from ( "picture" );
			$this->db->join ( "store", "store.id=picture.belongid" );
			$this->db->where ( 'type', 2 );
			$this->db->where ( 'store.manager', $member ['id'] );
			$eData ['photoCount'] = $this->db->count_all_results ();
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 7;
			$eConfig ['num_links'] = 7;
			$eConfig ['base_url'] = site_url ( 'member/photolist' );
			$eConfig ['total_rows'] = $eData ['photoCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			
			$this->load->view ( 'member/storepiclist', $eData );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	function photosave() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			
			$eConfig ['upload_path'] = 'uploadfile/' . date ( 'Y' ) . '/' . date ( 'W' ) . '/';
			
			$this->mkFolder ( $eConfig ['upload_path'] );
			$eConfig ['allowed_types'] = 'jpg|bmp|gif|png';
			$eConfig ['file_name'] = time () . rand ( 1000, 9999 );
			$eConfig ['max_size'] = 1024 * 20;
			
			$this->load->library ( 'upload', $eConfig );
			if (! $this->upload->do_upload ( 'cover' )) {
				header ( "Content-Type: text/html; charset=utf-8" );
				echo '<body style="margin: 0; padding: 0;">
					<div style="font-size: 12px; color: #CC3300;">
					' . $this->upload->display_errors () . '
					<a href="' . site_url ( 'member/avatar' ) . '">返回</a>
					</div>
					</body>';
			} else {
				
				$eUpLoad = $this->upload->data ();
				$eData ['imagePath'] = $eConfig ['upload_path'] . $eUpLoad ['file_name'];
				$eData ['title'] = $this->input->post ( 'album_name' );
				$eData ['desc'] = $this->input->post ( 'desc' );
				
				$type = $this->input->post ( 'type' );
				if (! isset ( $type ) || $type == null || $type == '') {
					$type = 1;
				}
				$eData ['type'] = $type;
				$eData ['createtime'] = time ();
				$eData ['updatetime'] = time ();
				$eData ['belongId'] = $member ['id'];
				$eData ['createid'] = $member ['id'];
				$eData ['updateid'] = $member ['id'];
				$eID = $this->db->insert ( 'picture', $eData );
				redirect ( 'member/photolist' );
			}
		
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	public function photodel() {
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$albumId = $this->input->post ( 'albumId' );
			$this->db->where ( 'id', $albumId );
			
			$this->db->delete ( 'picture' );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '删除相册成功';
			echo json_encode ( $ret );
		} else {
			redirect ( 'member/tologin' );
		}
	
	}
	
	function savetopic() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			$eData ['belongId'] = $this->input->post ( 'eID' );
			$eData ['title'] = $this->input->post ( 'title' );
			$eData ['content'] = $this->input->post ( 'info' );
			$eData ['type'] = $this->input->post ( 'type' );
			$eData ['creatid'] = $member ['id'];
			$eData ['creator'] = $member ['username'];
			$eData ['createtime'] = time ();
			
			$this->db->insert ( 'topic', $eData );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '写话题成功';
			echo json_encode ( $ret );
		} else {
			$ret ['success'] = 'false';
			$ret ['msg'] = '你没有登录，请登录';
			echo json_encode ( $ret );
		}
	}
	
	function savetag() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			$eData ['name'] = $this->input->post ( 'name' );
			$eData ['belongId'] = $this->input->post ( 'eID' );
			$eData ['type'] = $this->input->post ( 'type' );
			$eData ['creatid'] = $member ['id'];
			$eData ['creator'] = $member ['username'];
			$eData ['createtime'] = time ();
			
			$this->db->insert ( 'tag', $eData );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '写印象成功';
			echo json_encode ( $ret );
		} else {
			$ret ['success'] = 'false';
			$ret ['msg'] = '你没有登录，请登录';
			echo json_encode ( $ret );
		}
	}
	
	function love() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			$eData ['loveId'] = $this->input->post ( 'loveId' );
			$eData ['loveType'] = $this->input->post ( 'loveType' );
			$eData ['creatid'] = $member ['id'];
			
			$this->db->where ( 'loveId', $eData ['loveId'] );
			$this->db->where ( 'loveType', $eData ['loveType'] );
			$this->db->where ( 'creatid', $eData ['creatid'] );
			$loveCount = $this->db->count_all_results ( 'love' );
			
			if ($loveCount > 0) {
				$ret ['success'] = 'false';
				$ret ['msg'] = '你已经喜欢过了';
				echo json_encode ( $ret );
			} else {
				$eData ['creator'] = $member ['username'];
				$eData ['createtime'] = time ();
				
				$this->db->insert ( 'love', $eData );
				if ($eData ['loveType'] == '2') {
					$this->db->query ( 'UPDATE xd_store SET loves=loves+1 WHERE id=' . $eData ['loveId'] );
				} elseif ($eData ['loveType'] == '1') {
					$this->db->query ( 'UPDATE xd_street SET loves=loves+1 WHERE id=' . $eData ['loveId'] );
				}
				header ( "Content-Type: text/html; charset=utf-8" );
				
				$ret ['success'] = 'true';
				$ret ['msg'] = '喜欢成功';
				echo json_encode ( $ret );
			}
		
		} else {
			$ret ['success'] = 'false';
			$ret ['msg'] = '你没有登录，请登录';
			echo json_encode ( $ret );
		}
	}
	
	function favor() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			$eData ['favoriteId'] = $this->input->post ( 'favorId' );
			$eData ['favoriteType'] = $this->input->post ( 'favorType' );
			$eData ['member'] = $member ['id'];
			$eData ['createTime'] = time ();
			
			$this->db->where ( 'favoriteId', $eData ['favoriteId'] );
			$this->db->where ( 'favoriteType', $eData ['favoriteType'] );
			$this->db->where ( 'member', $eData ['member'] );
			$favorCount = $this->db->count_all_results ( 'favorite' );
			
			if ($favorCount > 0) {
				$ret ['success'] = 'false';
				$ret ['msg'] = '你已经收藏过了';
				echo json_encode ( $ret );
			} else {
				
				$this->db->insert ( 'favorite', $eData );
				if ($eData ['favoriteType'] == '2') {
					$this->db->query ( 'UPDATE xd_store SET favorites=favorites+1 WHERE id=' . $eData ['favoriteId'] );
				}
				header ( "Content-Type: text/html; charset=utf-8" );
				
				$ret ['success'] = 'true';
				$ret ['msg'] = '收藏成功';
				echo json_encode ( $ret );
			}
		
		} else {
			$ret ['success'] = 'false';
			$ret ['msg'] = '你没有登录，请登录';
			echo json_encode ( $ret );
		}
	}
	
	function savecomment() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			$eData ['belongId'] = $this->input->post ( 'belongId' );
			$eData ['content'] = $this->input->post ( 'content' );
			$eData ['type'] = $this->input->post ( 'type' );
			$eData ['creatid'] = $member ['id'];
			$eData ['creator'] = $member ['username'];
			$eData ['createtime'] = time ();
			
			$this->db->insert ( 'comment', $eData );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '评论成功';
			echo json_encode ( $ret );
		} else {
			$ret ['success'] = 'false';
			$ret ['msg'] = '你没有登录，请登录';
			echo json_encode ( $ret );
		}
	}
	
	function replycomment() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			$eData ['belongId'] = $this->input->post ( 'belongId' );
			$eData ['content'] = $this->input->post ( 'content' );
			$eData ['type'] = $this->input->post ( 'type' );
			$eData ['creatid'] = $member ['id'];
			$eData ['creator'] = $member ['username'];
			$eData ['createtime'] = time ();
			
			$this->db->insert ( 'comment', $eData );
			if ($eData ['type'] == '4') {
				$this->db->query ( 'UPDATE xd_comment SET replys=replys+1 WHERE id=' . $eData ['belongId'] );
			} elseif ($eData ['type'] == '5') {
				$this->db->query ( 'UPDATE xd_topic SET replys=replys+1 WHERE id=' . $eData ['belongId'] );
			}
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '回复成功';
			echo json_encode ( $ret );
		} else {
			$ret ['success'] = 'false';
			$ret ['msg'] = '你没有登录，请登录';
			echo json_encode ( $ret );
		}
	}
	function replytopic() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			$eData ['belongId'] = $this->input->post ( 'belongId' );
			$eData ['content'] = $this->input->post ( 'content' );
			$eData ['type'] = $this->input->post ( 'type' );
			$eData ['creatid'] = $member ['id'];
			$eData ['creator'] = $member ['username'];
			$eData ['createtime'] = time ();
			
			$this->db->insert ( 'comment', $eData );
			
			$this->db->query ( 'UPDATE xd_topic SET replys=replys+1 WHERE id=' . $eData ['belongId'] );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '回复成功';
			echo json_encode ( $ret );
		} else {
			$ret ['success'] = 'false';
			$ret ['msg'] = '你没有登录，请登录';
			echo json_encode ( $ret );
		}
	}
	
	function support() {
		if ($this->checklogin ()) {
			$eData = array ();
			$member = $this->session->userdata ( 'member' );
			$eData ['typeId'] = $this->input->post ( 'belongId' );
			$eData ['type'] = $this->input->post ( 'type' );
			$eData ['creater'] = $member ['id'];
			
			$this->db->where ( 'typeId', $eData ['typeId'] );
			$this->db->where ( 'type', $eData ['type'] );
			$this->db->where ( 'creater', $eData ['creater'] );
			$loveCount = $this->db->count_all_results ( 'support' );
			
			if ($loveCount > 0) {
				$ret ['success'] = 'false';
				if ('recommends' == $eData ['type']) {
					$ret ['msg'] = '你已经推荐过了';
				} else {
					$ret ['msg'] = '你已经支持过了';
				}
				
				echo json_encode ( $ret );
			} else {
				$eData ['createTime'] = time ();
				
				$this->db->insert ( 'support', $eData );
				
				$eData ['belongId'] = $this->input->post ( 'belongId' );
				$eData ['type'] = $this->input->post ( 'type' );
				
				if ($eData ['type'] == '4') {
					$this->db->query ( 'UPDATE xd_comment SET support=support+1 WHERE id=' . $eData ['belongId'] );
				} elseif ($eData ['type'] == '5') {
					$this->db->query ( 'UPDATE xd_topic SET support=support+1 WHERE id=' . $eData ['belongId'] );
				}
				header ( "Content-Type: text/html; charset=utf-8" );
				
				$ret ['success'] = 'true';
				$ret ['msg'] = '支持成功';
				echo json_encode ( $ret );
			}
		
		} else {
			$ret ['success'] = 'false';
			$ret ['msg'] = '你没有登录，请登录';
			echo json_encode ( $ret );
		}
	}
	
	function sendmsg() {
		$tamemberId = $this->input->get('id');
		if ($this->checklogin ()) {
			$eData = array();
			if($tamemberId != null){
				$this->db->where('id',$tamemberId);
				$eData['tamember'] = $this->db->get('member')->row_array();
				$eData['receiver'] = $eData['tamember']['username'];
				$eData['title'] = '';
				$eData['content'] = '';
			}else{
				$eData['receiver'] = '';
				$eData['title'] = '';
				$eData['content'] = '';
			}
			
			$this->load->view ( 'member/sendmsg' ,$eData);
		} else {
			redirect ( 'member/tologin?gourl='.site_url('member/sendmsg?id='.$tamemberId));
		}
	}
	
	function savemsg(){
		$receiver = $this->input->post ( 'receiver' );
		$eData ['title'] = $this->input->post ( 'title' );
		$eData ['content'] = $this->input->post ( 'info' );
		$receiveMember = null;
		if ($this->checklogin ()) {
			$this->db->where('username',$receiver);
			$receiveMember = $this->db->get('member')->row_array();
			if($receiveMember == null){
				$eData ['errormsg'] = '接收者不存在！';
				$eData['receiver'] = $receiver;
				$eData['title'] = $eData ['title'];
				$eData['content'] = $eData ['content'];
				$this->load->view ( 'member/sendmsg' ,$eData);
				
			}else{
				$member = $this->session->userdata ( 'member' );
				$eData ['sender'] = $member['id'];
				$eData ['receiver'] = $receiveMember['id'];
				$eData ['createid'] = $member ['id'];
				$eData ['creator'] = $member ['username'];
				$eData ['createtime'] = time ();
				
				
				$eData ['boxtype'] = 1;
				$eData ['member'] = $receiveMember['id'];
				$eData ['isread'] = 0;
				$this->db->insert ( 'message', $eData );
				
				$eData ['boxtype'] = 2;
				$eData ['member'] = $member['id'];
				$eData ['isread'] = 1;
				$this->db->insert ( 'message', $eData );
				
				redirect ( 'member/sendbox');
			}
			
			
		} else {
			redirect ( 'member/tologin?gourl='.site_url('member/sendmsg?id='.$tamemberId));
		}
	}
	
	function sendbox(){
		if ($this->checklogin ()) {
			$ePage = ( int ) $this->input->get ( 'page' );
			$member = $this->session->userdata ( 'member' );
			$this->db->select ( "message.*,member.username" );
			$this->db->from ( "message" );
			$this->db->join ( "member", "member.id=message.receiver" );
			$this->db->where ( 'message.member', $member['id'] );
			$this->db->where ( 'message.boxtype', 2 );
			$this->db->limit ( 7, $ePage );
			$this->db->order_by ( 'message.createtime', 'DESC' );
			$messageList = $this->db->get ()->result_array ();
			$eData ['messageList'] = $messageList;
			
			$this->db->select ( "*" );
			$this->db->from ( "message" );
			$this->db->where ( 'message.member', $member['id'] );
			$this->db->where ( 'message.boxtype', 2 );
			$eData ['messageCount'] = $this->db->count_all_results ();
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 7;
			$eConfig ['num_links'] = 7;
			$eConfig ['base_url'] = site_url ( 'member/sendbox?1=1' );
			$eConfig ['total_rows'] = $eData ['messageCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			$this->load->view ( 'member/sendbox' ,$eData);
		} else {
			redirect ( 'member/tologin?gourl='.site_url('member/sendmsg?id='.$tamemberId));
		}
	}
	
	function receivebox(){
		if ($this->checklogin ()) {
			$ePage = ( int ) $this->input->get ( 'page' );
			$member = $this->session->userdata ( 'member' );
			$this->db->select ( "message.*,member.username" );
			$this->db->from ( "message" );
			$this->db->join ( "member", "member.id=message.sender" );
			$this->db->where ( 'message.member', $member['id'] );
			$this->db->where ( 'message.boxtype', 1 );
			$this->db->limit ( 7, $ePage );
			$this->db->order_by ( 'message.createtime', 'DESC' );
			$messageList = $this->db->get ()->result_array ();
			$eData ['messageList'] = $messageList;
			
			$this->db->select ( "*" );
			$this->db->from ( "message" );
			$this->db->where ( 'message.member', $member['id'] );
			$this->db->where ( 'message.boxtype', 1 );
			$eData ['messageCount'] = $this->db->count_all_results ();
			
			$this->load->library ( 'pagination' );
			$eConfig ['per_page'] = 7;
			$eConfig ['num_links'] = 7;
			$eConfig ['base_url'] = site_url ( 'member/receivebox?1=1' );
			$eConfig ['total_rows'] = $eData ['messageCount'];
			$eConfig ['first_link'] = false;
			$eConfig ['last_link'] = false;
			$eConfig ['next_link'] = '下一页';
			$eConfig ['next_tag_open'] = '<div class="def_btn_s3">';
			$eConfig ['next_tag_close'] = '</div>';
			$eConfig ['prev_link'] = '上一页';
			$eConfig ['prev_tag_open'] = '<div class="def_btn_s3 mr5">';
			$eConfig ['prev_tag_close'] = '</div>';
			$eConfig ['display_pages'] = FALSE; //不显示数字链接
			$this->pagination->initialize ( $eConfig );
			$this->load->view ( 'member/receivebox' ,$eData);
		} else {
			redirect ( 'member/tologin?gourl='.site_url('member/sendmsg?id='.$tamemberId));
		}
	}
	
	function delmessage(){
		if ($this->checklogin ()) {
			$member = $this->session->userdata ( 'member' );
			$messageId = $this->input->post ( 'messageId' );
			$this->db->where ( 'id', $messageId );
			
			$this->db->delete ( 'message' );
			
			header ( "Content-Type: text/html; charset=utf-8" );
			
			$ret ['success'] = 'true';
			$ret ['msg'] = '删除消息成功';
			echo json_encode ( $ret );
		} else {
			redirect ( 'member/tologin' );
		}
	}
	
	public function checkLoginJson() {
		$member = $this->session->userdata ( 'member' );
		header ( "Content-Type: text/html; charset=utf-8" );
		if ($member == null) {
			echo json_encode ( false );
		} else {
			echo json_encode ( true );
		}
	}
	
	
	function mkFolder($path) {
		if (! file_exists ( $path )) {
			$this->mkFolder ( dirname ( $path ) );
			mkdir ( $path, 0777 );
		}
	}
	
}

